/*
 * 创建组件的整体的声明导出文件
 * */
import { resolve } from "path";
import { FsFile } from "./utils/FsFile.js";
import { log } from "./utils/utils.js";
import { dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { LIB_NAME } from "../build/buildLib.js";
import { createComponentsDtsTemplate } from "./templates/index.js";

const __filename = fileURLToPath(import.meta.url);
const __dirname = resolve(dirname(__filename), `../${LIB_NAME}/dist/types`);

// 文件根目录
const FILE_ROOT_PATH = __dirname;

// 创建文件对象
const fsFile = new FsFile(FILE_ROOT_PATH);

export async function createComponentsDts() {
  // 创建的文件路径
  const componentPath = resolve(FILE_ROOT_PATH, "./components"); // 组件文件夹
  const componentList = await fsFile.getFolderNames(componentPath); // 获取文件夹列表,组件列表
  const template = createComponentsDtsTemplate(componentList);
  const filePath = resolve(FILE_ROOT_PATH, "components.d.ts");
  return fsFile.createFile(filePath, template);
}

await createComponentsDts();
